package com.heima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.WmChannelMapper;
import com.heima.admin.service.WmChannelService;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.model.wemedia.pojos.WmNews;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
@Slf4j
public class WmChannelServiceImpl extends ServiceImpl<WmChannelMapper, WmChannel> implements WmChannelService {


    //用于自媒体端的下拉框选择
    @Override
    public ResponseResult findAll() {
        return ResponseResult.okResult(list());
    }

//    @Override
//    public ResponseResult addChannel(WmChannel wmChannel) {
//        if (wmChannel == null) {
//            log.warn("频道参数为空");
//            return ResponseResult.okResult(AppHttpCodeEnum.PARAM_INVALID);
//        }
//
//        // 检查频道名称是否重复
//        if (isChannelNameDuplicate(wmChannel.getName())) {
//            log.warn("频道名称重复：{}", wmChannel.getName());
//            return ResponseResult.okResult(AppHttpCodeEnum.CHANNEL_NAME_EXIST); // 或者抛出一个自定义异常
//        }
//
//        log.info("新增频道：{}", wmChannel);
//        save(wmChannel);
//        log.info("新增频道成功");
//        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
//    }

//    /**
//     * 检查频道名称是否重复
//     */
//    private boolean isChannelNameDuplicate(String channelName) {
//        // 查询数据库中是否有重复的频道名称
//        WmChannel existingChannel = findChannelByName(channelName);
//        //返回true 表示在数据库中找到与传入的 channelName 相同的频道名称，表示频道名称是重复的。
//        return existingChannel != null;
//    }

//    /**
//     * 根据名称查找频道
//     */
//    @Override
//    public WmChannel findChannelByName(String channelName) {
//        return getOne(lambdaQuery().eq(WmChannel::getName, channelName));
//    }


}